Skip to content

Conversation

@lnicola
Copy link
Member

@lnicola lnicola commented Dec 18, 2020

Fixes #6926

@lnicola
Copy link
Member Author

lnicola commented Dec 18, 2020

I'm pretty sure this isn't the right solution, though...

@lnicola lnicola force-pushed the mbe-placeholders branch 2 times, most recently from 3171d61 to 3e17346 Compare December 18, 2020 16:24
@lnicola lnicola changed the title Handle placeholders in mbe Handle $_ in mbe Dec 18, 2020
fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> ExpandResult<Fragment> {
fn expand_var(ctx: &mut ExpandCtx, v: Option<&SmolStr>) -> ExpandResult<Fragment> {
let underscore = SmolStr::new_inline("_");
let v = v.unwrap_or(&underscore);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all awkward because name: &'a SmolStr so we can't make a new one when needed.

@lnicola
Copy link
Member Author

lnicola commented Dec 18, 2020

And apparently $__:tt ends up as Ident...

@matklad matklad requested a review from edwin0cheng December 19, 2020 13:35
@edwin0cheng
Copy link
Contributor

I'm pretty sure this isn't the right solution, though...

Yeah, I am pretty sure we didn't handle underscore as special case in mbe. So let me check what's happened in this week end?

@edwin0cheng
Copy link
Contributor

Oh, I understand why now.

https://github.com/rust-analyzer/rust-analyzer/blob/067067a6c11bb5afda98f5af14bfdec4744e7812/crates/parser/src/syntax_kind/generated.rs#L269-L279

We treat underscore as punct . But why it is a punct ? It should not be right ?

@edwin0cheng
Copy link
Contributor

If we have to make it to punct for parser, I recommend the following changes:

https://github.com/rust-analyzer/rust-analyzer/blob/7f3ba7d57fd2f43f3cfc012f898a26d940bf5cc8/crates/mbe/src/syntax_bridge.rs#L316

Change to

result.push(if k.is_punct() && k != UNDERSCORE {

and

https://github.com/rust-analyzer/rust-analyzer/blob/7f3ba7d57fd2f43f3cfc012f898a26d940bf5cc8/crates/mbe/src/syntax_bridge.rs#L380-L381

Add:

IDENT => make_leaf!(Ident),
UNDERSCORE => make_leaf!(Ident),   // <---
k if k.is_keyword() => make_leaf!(Ident),

@lnicola
Copy link
Member Author

lnicola commented Dec 20, 2020

Thanks for the pointers, that doesn't seem to break anything else.

@edwin0cheng
Copy link
Contributor

LGTM, bors r+

@edwin0cheng
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 20, 2020

@bors bors bot merged commit 87886e8 into rust-lang:master Dec 20, 2020
@lnicola lnicola deleted the mbe-placeholders branch December 20, 2020 06:41
bors bot added a commit that referenced this pull request Dec 28, 2020
7059: Special case $_ in meta var instead of treat it as ident in mbe  r=lnicola a=edwin0cheng

In #6929, we treat '_' as an ident but rustc is only allow it in some special places (e.g. meta var in mbe , type, pat etc). 

This PR rollback that and we only make '$_' works in meta var matching. 

Fixes #7056 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$_ is rejected in MBE (gtk-rs clone!)

2 participants